/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package comandaXM.vista.auxiliars;

import comandaXM.utils.TDSLanguageUtils;
import comandaXM.utils.ValidarText;
import comandaXM.utils.eventXM.IListenerXM;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;


/**
 *
 * @author xmarti
 */
public abstract class JPAuxiliarTipusPagament extends javax.swing.JPanel implements IListenerXM{

    private List listeners = new ArrayList();
    public JPAuxiliarTipusPagament() {
        initComponents();        
        this.jTextCode.setDocument(new ValidarText(10,false,true));       
        this.jTextName.setDocument(new ValidarText(25,false,true));
        this.jTextDies.setDocument(new ValidarText(3,true));
        this.jTextDiaPagament.setDocument(new ValidarText(3,true)); 
    }
    public String getCode(){
        return this.jTextCode.getText();        
    }
    public void setCode(String code){
        this.jTextCode.setText(code);      
        this.jTextCode.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 10, 1, 1));
        this.jLabelCodeERR.setVisible(false);
    }  
    public void setErrorCode(String err ){
       this.jLabelCodeERR.setText(err);
       this.jLabelCodeERR.setVisible(true); 
       this.jTextCode.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 10, 1, 1, java.awt.Color.red));       
    }
    public String getDiaPagament(){
        if (jTextDiaPagament.getText()== "" ) return "25";
        return this.jTextDiaPagament.getText();        
    }
    public void setDiaPagament(String code){
        this.jTextDiaPagament.setText(code);                
    }
    public void setRequestFocus(){
        this.jTextCode.requestFocus();
        this.jTextCode.select(0, this.jTextCode.getText().length());
    }
    
    public String getNameAuxiliar (){
        return this.jTextName.getText();
    }
    public void setNameAuxiliar(String name){
        this.jTextName.setText(name);
        this.jTextName.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 10, 1, 1));
        this.jLabelCodeERR1.setVisible(false);
    }    
    public void setErrorName(String err ){
       this.jLabelCodeERR1.setText(err);
       this.jLabelCodeERR1.setVisible(true); 
       this.jTextName.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 10, 1, 1, java.awt.Color.red));       
    }       
    public String getDies (){
        return this.jTextDies.getText();
    }
    public void setDies(String name){
        this.jTextDies.setText(name);
        this.jTextDies.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 10, 1, 1));
        this.jLabelCodeERRImpost.setVisible(false);
    }    
    public void setErrorDies(String err ){
       this.jLabelCodeERRImpost.setText(err);
       this.jLabelCodeERRImpost.setVisible(true); 
       this.jTextDies.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 10, 1, 1, java.awt.Color.red));       
    }
    public boolean getEstat() {
        return this.jXecEstat.isSelected(); 
    }
    public void setEstat(boolean estat){
        this.jXecEstat.setSelected(estat);
    }
    
     public synchronized void addKeyCodeListener(IListenerXM listener){
        listeners.add(listener); 
    }
    public synchronized void removeKeyCodeListener (IListenerXM listener){
        listeners.remove(listener); 
    }
    protected void notifyKeyPressed (int increment){
        List tempList; 
        synchronized (this){
            tempList= (List)((ArrayList)listeners).clone(); 
        }
      for (Iterator it= tempList.iterator();it.hasNext();){
         ((IListenerXM) it.next()).movePosition(increment); 
      }
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTextCode = new javax.swing.JTextField();
        jLabelDescription = new javax.swing.JLabel();
        jTextName = new javax.swing.JTextField();
        jTextDiaPagament = new javax.swing.JTextField();
        jLabelCaptionName2 = new javax.swing.JLabel();
        jLabelCodeERR = new javax.swing.JLabel();
        jLabelCodeERRImpost = new javax.swing.JLabel();
        jTextDies = new javax.swing.JTextField();
        jLabelCaptionName3 = new javax.swing.JLabel();
        jLabelCodeERR1 = new javax.swing.JLabel();
        jLabelCaptionName4 = new javax.swing.JLabel();
        jXecEstat = new javax.swing.JCheckBox();

        setLayout(null);

        jTextCode.setBackground(new java.awt.Color(255, 255, 204));
        jTextCode.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jTextCode.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTextCode.setAlignmentX(0.0F);
        jTextCode.setAlignmentY(0.0F);
        jTextCode.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        jTextCode.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextCodeKeyPressed(evt);
            }
        });
        add(jTextCode);
        jTextCode.setBounds(100, 10, 60, 33);

        jLabelDescription.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelDescription.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabelDescription.setText(TDSLanguageUtils.getMessage("jPanelAuxiliarTipusPagament.JLabel.name.caption"));
        add(jLabelDescription);
        jLabelDescription.setBounds(10, 50, 80, 33);

        jTextName.setBackground(new java.awt.Color(255, 255, 204));
        jTextName.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jTextName.setAlignmentX(0.0F);
        jTextName.setAlignmentY(0.0F);
        jTextName.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 10, 1, 1, java.awt.Color.red));
        jTextName.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextNameKeyPressed(evt);
            }
        });
        add(jTextName);
        jTextName.setBounds(100, 50, 200, 33);

        jTextDiaPagament.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jTextDiaPagament.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTextDiaPagament.setAlignmentX(0.0F);
        jTextDiaPagament.setAlignmentY(0.0F);
        jTextDiaPagament.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        jTextDiaPagament.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextDiaPagamentKeyPressed(evt);
            }
        });
        add(jTextDiaPagament);
        jTextDiaPagament.setBounds(100, 130, 60, 33);

        jLabelCaptionName2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelCaptionName2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabelCaptionName2.setText(TDSLanguageUtils.getMessage("jPanelAuxiliarTipusPagament.JLabel.code.caption"));
        add(jLabelCaptionName2);
        jLabelCaptionName2.setBounds(10, 10, 80, 33);

        jLabelCodeERR.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelCodeERR.setForeground(java.awt.Color.red);
        jLabelCodeERR.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        add(jLabelCodeERR);
        jLabelCodeERR.setBounds(190, 10, 220, 33);

        jLabelCodeERRImpost.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelCodeERRImpost.setForeground(java.awt.Color.red);
        jLabelCodeERRImpost.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        add(jLabelCodeERRImpost);
        jLabelCodeERRImpost.setBounds(190, 90, 220, 33);

        jTextDies.setBackground(new java.awt.Color(255, 255, 204));
        jTextDies.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jTextDies.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTextDies.setAlignmentX(0.0F);
        jTextDies.setAlignmentY(0.0F);
        jTextDies.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        jTextDies.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextDiesKeyPressed(evt);
            }
        });
        add(jTextDies);
        jTextDies.setBounds(100, 90, 60, 33);

        jLabelCaptionName3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelCaptionName3.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabelCaptionName3.setText(TDSLanguageUtils.getMessage("jPanelAuxiliarTipusPagament.JLabel.dies.caption"));
        add(jLabelCaptionName3);
        jLabelCaptionName3.setBounds(10, 90, 80, 33);

        jLabelCodeERR1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelCodeERR1.setForeground(java.awt.Color.red);
        jLabelCodeERR1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        add(jLabelCodeERR1);
        jLabelCodeERR1.setBounds(310, 50, 220, 33);

        jLabelCaptionName4.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelCaptionName4.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabelCaptionName4.setText(TDSLanguageUtils.getMessage("jPanelAuxiliarTipusPagament.JLabel.diaPagament.caption"));
        add(jLabelCaptionName4);
        jLabelCaptionName4.setBounds(10, 130, 80, 33);

        jXecEstat.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jXecEstat.setText(TDSLanguageUtils.getMessage("jPanelAuxiliarTipusPagament.JLabel.estat.caption"));
        add(jXecEstat);
        jXecEstat.setBounds(200, 140, 100, 23);
    }// </editor-fold>//GEN-END:initComponents

    private void jTextCodeKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextCodeKeyPressed
       if (evt.getKeyCode()==38){
           notifyKeyPressed(-1);  
       }else if (evt.getKeyCode()==40){
           notifyKeyPressed(1);  
       }
    }//GEN-LAST:event_jTextCodeKeyPressed

    private void jTextNameKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextNameKeyPressed
       if (evt.getKeyCode()==38){
           notifyKeyPressed(-1);  
       }else if (evt.getKeyCode()==40){
           notifyKeyPressed(1);  
       }
    }//GEN-LAST:event_jTextNameKeyPressed

    private void jTextDiesKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextDiesKeyPressed
       if (evt.getKeyCode()==38){
           notifyKeyPressed(-1);  
       }else if (evt.getKeyCode()==40){
           notifyKeyPressed(1);  
       }
    }//GEN-LAST:event_jTextDiesKeyPressed

    private void jTextDiaPagamentKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextDiaPagamentKeyPressed
       if (evt.getKeyCode()==38){
           notifyKeyPressed(-1);  
       }else if (evt.getKeyCode()==40){
           notifyKeyPressed(1);  
       }
    }//GEN-LAST:event_jTextDiaPagamentKeyPressed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabelCaptionName2;
    private javax.swing.JLabel jLabelCaptionName3;
    private javax.swing.JLabel jLabelCaptionName4;
    private javax.swing.JLabel jLabelCodeERR;
    private javax.swing.JLabel jLabelCodeERR1;
    private javax.swing.JLabel jLabelCodeERRImpost;
    private javax.swing.JLabel jLabelDescription;
    private javax.swing.JTextField jTextCode;
    private javax.swing.JTextField jTextDiaPagament;
    private javax.swing.JTextField jTextDies;
    private javax.swing.JTextField jTextName;
    private javax.swing.JCheckBox jXecEstat;
    // End of variables declaration//GEN-END:variables
}
